<template>
	<sc-drawer
		v-model="visible"
		title="添加资源"
		size="700px"
		@cancel="$emit('close')"
		@confirm="confirm"
	>
		<clueInfoForm ref="clueInfoRef" v-model:clueInfo="clueInfo" />
	</sc-drawer>
</template>

<script setup>
import { ref, getCurrentInstance,defineEmits,onMounted } from "vue";
import { ElMessage } from "element-plus";
import clueInfoForm from "@/views/clue/components/clue-Info-form/index.vue";
const { proxy } = getCurrentInstance();

const visible = ref(true);

const clueInfo = ref({});
const clueInfoRef = ref(null);
const emits = defineEmits(['reload'])

const confirm = () => {

	const paramsObj = { ...clueInfoRef.value.paramsData, ...clueInfo.value };
	console.log("confirm", paramsObj);
	if(!paramsObj.headPic){
		delete paramsObj.headPic
	}
	if(!paramsObj.picture){
		delete paramsObj.picture
	}
	var newContactsInfos = Array.from(paramsObj.contactsInfos);
	var newContactsInfos1 = [];
	newContactsInfos.forEach(item => {
		newContactsInfos1.push(JSON.parse(JSON.stringify(item)));
	})
	paramsObj.contactsInfos = newContactsInfos1;
	proxy.$API.clue.add.get(paramsObj).then((res) => {
		visible.value = false;
		if(res.code && res.code == 200){
			ElMessage({
				message: "添加资源成功",
				type: "success",
			});
			emits('reload')
		}else{
			ElMessage({
				message: res.message,
				type: "error",
			});
		}
	});
};
</script>

<style lang="scss" scoped>
.mr10 {
	margin-right: 10px;
}
</style>
